﻿using Ensemble_Windows.UI;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Ensemble_Windows
{
    /// <summary>
    /// UI帮助类
    /// </summary>
    public static class Helpers
    {
        /// <summary>
        /// FlatColor
        /// </summary>
        public static Color BaseColor = Color.FromArgb(35, 168, 109);
        /// <summary>
        /// TextColor
        /// </summary>
        public static Color TextColor = Color.FromArgb(243, 243, 243);
        /// <summary>
        /// TextLight
        /// </summary>
        public static Color TextLight = Color.FromArgb(45, 47, 49);
        /// <summary>
        /// BorderColor
        /// </summary>
        public static Color BorderColor = Color.FromArgb(53, 58, 60);
        /// <summary>
        /// BaseLight
        /// </summary>
        public static Color BaseLight = Color.FromArgb(196, 199, 200);
        /// <summary>
        /// HeaderLight
        /// </summary>
        public static Color HeaderLight = Color.FromArgb(171, 171, 172);
        /// <summary>
        /// HeaderColor
        /// </summary>
        public static Color HeaderColor = Color.FromArgb(45, 47, 49);
        /// <summary>
        /// DarkerProgress
        /// </summary>
        public static Color DarkerProgress = Color.FromArgb(23, 148, 92);

        /// <summary>
        /// NearSF
        /// </summary>
        public static readonly StringFormat NearSF = new StringFormat
        {
            Alignment = StringAlignment.Near,
            LineAlignment = StringAlignment.Near
        };
        
        /// <summary>
        /// CenterSF
        /// </summary>
        public static readonly StringFormat CenterSF = new StringFormat
        {
            Alignment = StringAlignment.Center,
            LineAlignment = StringAlignment.Center
        };
        /// <summary>
        /// 获取颜色
        /// </summary>
        /// <param name="control">控件</param>
        /// <returns>颜色</returns>
        public static Colors GetColors(Control control)
        {
            if (control == null)
                throw new ArgumentNullException();

            Colors colors = new Colors();

            while (control != null && (control.GetType() != typeof(FormSkin)))
            {
                control = control.Parent;
            }

            if (control != null)
            {
                FormSkin skin = (FormSkin)control;
                colors.Base = skin.FlatColor;
            }

            return colors;
        }
        
        /// <summary>
        /// RoundRec
        /// </summary>
        /// <param name="Rectangle"></param>
        /// <param name="Curve"></param>
        /// <returns></returns>
        public static GraphicsPath RoundRec(Rectangle Rectangle, int Curve)
        {
            GraphicsPath P = new GraphicsPath();
            int ArcRectangleWidth = Curve * 2;
            P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90);
            P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90);
            P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90);
            P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90);
            P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y));
            return P;
        }

        /// <summary>
        /// DrawArrow
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="flip"></param>
        /// <returns></returns>
        public static GraphicsPath DrawArrow(int x, int y, bool flip)
        {
            GraphicsPath GP = new GraphicsPath();

            int W = 12;
            int H = 6;

            if (flip)
            {
                GP.AddLine(x + 1, y, x + W + 1, y);
                GP.AddLine(x + W, y, x + H, y + H - 1);
            }
            else
            {
                GP.AddLine(x, y + H, x + W, y + H);
                GP.AddLine(x + W, y + H, x + H, y);
            }

            GP.CloseFigure();
            return GP;
        }
    }
}
